<?php

namespace App\Http\Controllers;

use App\Models\Customer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;

class CustomerController extends Controller
{
    public function index()
    {
        $customers = Customer::query()->select('*')->with(
            [
                'orders'=>function($query){
                    return $query->select('*');
                }
            ]
        )->get();
        return Inertia::render('Booking/Customer', [
            'customers' => $customers
        ]);
    }


    public function update(Request $request): \Illuminate\Http\RedirectResponse
    {
        $data = $request->all();
        $id = $data['id'];
        Customer::dataSave($data, $id);

        return Redirect::route('customer');
    }

    public function delete(Request $request): \Illuminate\Http\RedirectResponse
    {
        $id = $request->get('id');
        Customer::query()->find($id)->delete();

        return Redirect::route('customer');
    }
}
